package com.example.message.mq;

import com.example.message.config.RabbitMQConfig;
import com.example.message.feign.BiddingFeign;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Date;

/**
 * @author 小许
 * @Title:
 * @Package
 * @Description:
 * @date 2020/11/24-17:53
 */
@Component
public class MessageReceiver {
    @Autowired
    private BiddingFeign biddingFeign;

    /**
     * 监听死信队列  走逻辑判断，尚未支付且超过过期时间的订单号设置为失效订单
     *
     * @param message 信息
     */
    @RabbitListener(queuesToDeclare = @Queue(RabbitMQConfig.PROCESS_QUEUE))
    public void listener(String message) {
        // 从队列中取出订单号
        String orderNo = message;
        biddingFeign.closeLoan(orderNo);
        System.out.println(new Date() + "消费消息，订单号为" + orderNo);
    }
}
